#ifndef _WX_DEBUGRPT_H_
#define _WX_DEBUGRPT_H_

#include "wx/defs.h"
#include "wx/string.h"
#include "wx/arrstr.h"

class wxXmlNode;

class wxDebugReport {
  public:
    enum Context {
      Context_Current,
      Context_Exception
    };
    wxDebugReport();
    virtual ~wxDebugReport();
    const wxString& GetDirectory() const { return m_dir; }
    bool IsOk() const { return !GetDirectory().empty(); }
    void Reset() { m_dir.clear(); }
    virtual void AddFile( const wxString& filename, const wxString& description );
    bool AddText( const wxString& filename, const wxString& text, const wxString& description );
    bool AddCurrentContext() { return AddContext( Context_Current ); }
    bool AddExceptionContext() { return AddContext( Context_Exception ); }
    virtual bool AddContext( Context ctx );
    void AddAll( Context context = Context_Exception );
    bool Process();
    virtual wxString GetReportName() const;
    size_t GetFilesCount() const { return m_files.GetCount(); }
    bool GetFile( size_t n, wxString *name, wxString *desc ) const;
    void RemoveFile( const wxString& name );
  protected:
    virtual bool DoAddSystemInfo( wxXmlNode *nodeSystemInfo );
    virtual bool DoAddLoadedModules( wxXmlNode *nodeModules );
    virtual bool DoAddExceptionInfo( wxXmlNode *nodeContext );
    virtual void DoAddCustomContext( wxXmlNode * ( nodeRoot ) ) { }
    virtual bool DoProcess();
  private:
    wxString m_dir;
    wxArrayString m_files, m_descriptions;
};

class wxDebugReportCompress : public wxDebugReport {
  public:
    wxDebugReportCompress() { }
    const wxString& GetCompressedFileName() const { return m_zipfile; }

  protected:
    virtual bool DoProcess();
  private:
    wxString m_zipfile;
};

class wxDebugReportUpload : public wxDebugReportCompress {
  public:
    wxDebugReportUpload( const wxString& url, const wxString& input, const wxString& action,
                         const wxString& curl = wxT( "curl" ) );
  protected:
    virtual bool DoProcess();
    virtual bool OnServerReply( const wxArrayString & ( reply ) ) {
      return true;
    }

  private:
    wxString m_uploadURL;
    wxString m_inputField;
    wxString m_curlCmd;
};

class wxDebugReportPreview {
  public:
    // ctor is trivial
    wxDebugReportPreview() { }
    virtual bool Show( wxDebugReport& dbgrpt ) const = 0;
    virtual ~wxDebugReportPreview() { }
};

class wxDebugReportPreviewStd : public wxDebugReportPreview {
  public:
    wxDebugReportPreviewStd() { }

    virtual bool Show( wxDebugReport& dbgrpt ) const;
};

#endif // _WX_DEBUGRPT_H_
